﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using iTeachSoft.CoreObjects;
using System.Windows.Forms;
using iTeachSoft.Presentation.Code.Managers;

namespace iTeachSoft.Presentation.Dialogs
{
    /// <summary>
    /// Interaction logic for DialogSlideProperties.xaml
    /// </summary>
    public partial class DialogSlideProperties : Window
    {
        private Slide mCurrentSlide = null;

        public DialogSlideProperties(Slide slide)
        {
            InitializeComponent();

            mCurrentSlide = slide;
            ReflactCurrentSlide();

            this.buttonOk.Click += new RoutedEventHandler(buttonOk_Click);
            this.buttonCancel.Click += new RoutedEventHandler(buttonCancel_Click);
            this.buttonBrowse.Click += new RoutedEventHandler(buttonBrowse_Click);
        }

        private void ReflactCurrentSlide()
        {
            textBoxImagePath.Text = mCurrentSlide.BackgroundPath;
            textBoxWidth.Text = mCurrentSlide.Size.Width.ToString();
            textBoxHeight.Text = mCurrentSlide.Size.Height.ToString();
            textBoxShowFor.Text = mCurrentSlide.ShowSlideForSeconds.ToString("0.0");
        }

        private void UpdateCurrentSlide()
        {
            mCurrentSlide.BackgroundPath = textBoxImagePath.Text;
            
            int width = int.Parse(textBoxWidth.Text);
            int height = int.Parse(textBoxHeight.Text);
            float showFor = float.Parse(textBoxShowFor.Text);

            mCurrentSlide.Size = new System.Drawing.Size(width, height);
            mCurrentSlide.ShowSlideForSeconds = showFor;
        }

        void buttonBrowse_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlgOpenFile = new OpenFileDialog();
            if (dlgOpenFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBoxImagePath.Text = dlgOpenFile.FileName;
            }
        }

        void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        void buttonOk_Click(object sender, RoutedEventArgs e)
        {
            UpdateCurrentSlide();
            this.Close();

            EventsManagement.Instance.OnReflectProjectInvoked(this, EventArgs.Empty);
        }


    }
}
